import Vue from 'vue'

Vue.use({
    install(Vue) {
        Vue.prototype.StaticFunc = {
            reader(_this, keyId, val) {
                let title = val;
                let data = _this.$store.state.params[keyId];
                if (!!data) {
                    data.forEach(item => {
                        if (item.keyId == val) {
                            title = item.title;
                            return title;
                        }
                    });
                }
                return title;
            },
            dyAlert(code, _this, data, back) {
                if (data.code != code) {
                    _this.$Modal({
                        closeOnMask: false,
                        content: `<div class=""><i class="red-color h-icon-error"></i>&nbsp;&nbsp;` + data.msg + `</div>`,
                    });
                    return;
                }
                _this.$Modal({
                    closeOnMask: false,
                    content: `<div class=""><i class="primary-color h-icon-success"></i>&nbsp;&nbsp;` + data.msg + `</div>`,
                    buttons: [{
                        type: 'ok',
                        name: '确认',
                        color: 'primary'
                    }],
                    events: {
                        ok: (modal) => {
                            modal.close();
                            if (back != false) {
                                _this.$router.back();
                            } else {
                                _this.$bus.$emit("ReloadData");
                            }
                        },
                    }
                });
            },
            split(data) {
                if (!!data && data.indexOf(",") != -1) {
                    data = data.split(",");
                    return data;
                }
                return [data];
            },
            join(data) {
                if (!!data && data instanceof Array && data.length > 0) {
                    data = data.join(",");
                }
                return data;
            }
        };
    }
});